package com.hjm.project.merchantInfo.merchantRate.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.merchantInfo.merchantRate.domain.MerchantRate;
import com.hjm.project.merchantInfo.merchantRate.service.IMerchantRateService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 商户费率绑定Controller
 * 
 * @author maker-platform
 * @date 2024-04-15
 */
@Controller
@RequestMapping("/merchantInfo/merchantRate")
public class MerchantRateController extends BaseController {
    private String prefix = "merchantInfo/merchantRate";

    @Resource
    private IMerchantRateService merchantRateService;

    @RequiresPermissions("merchantInfo:merchantRate:view")
    @GetMapping()
    public String merchantRate() {
        return prefix + "/merchantRate";
    }

    /**
     * 查询商户费率绑定列表
     */
    @RequiresPermissions("merchantInfo:merchantRate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerchantRate merchantRate) {
        startPage();
        List<MerchantRate> list = merchantRateService.selectMerchantRateList(merchantRate);
        return getDataTable(list);
    }

    /**
     * 导出商户费率绑定列表
     */
    @RequiresPermissions("merchantInfo:merchantRate:export")
    @Log(title = "商户费率绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerchantRate merchantRate) {
        List<MerchantRate> list = merchantRateService.selectMerchantRateList(merchantRate);
        ExcelUtil<MerchantRate> util = new ExcelUtil<MerchantRate>(MerchantRate.class);
        return util.exportExcel(list, "merchantRate");
    }

    /**
     * 新增商户费率绑定
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户费率绑定
     */
    @RequiresPermissions("merchantInfo:merchantRate:add")
    @Log(title = "商户费率绑定", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerchantRate merchantRate) {
        return toAjax(merchantRateService.insertMerchantRate(merchantRate));
    }

    /**
     * 修改商户费率绑定
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        MerchantRate merchantRate = merchantRateService.selectMerchantRateById(id);
        mmap.put("merchantRate", merchantRate);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户费率绑定
     */
    @RequiresPermissions("merchantInfo:merchantRate:edit")
    @Log(title = "商户费率绑定", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerchantRate merchantRate) {
        return toAjax(merchantRateService.updateMerchantRate(merchantRate));
    }

    /**
     * 删除商户费率绑定
     */
    @RequiresPermissions("merchantInfo:merchantRate:remove")
    @Log(title = "商户费率绑定", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(merchantRateService.deleteMerchantRateByIds(ids));
    }
}
